package test

import (
	"fmt"
)

func main() {

	// 创建一个新的结构体
	fmt.Println(Books{"Go 语言", "www.runoob.com", "Go 语言教程", 6495407})
	// 也可以使用 key => value 格式
	fmt.Println(Books{title: "Go 语言", author: "www.runoob.com", subject: "Go 语言教程", bookId: 6495407})
	// 忽略的字段为 0 或 空
	fmt.Println(Books{title: "Go 语言", author: "www.runoob.com"})

	printBook01()

}

func printBook01() {

	var book1 Books /* 声明 Book1 为 Books 类型 */
	var book2 Books /* 声明 Book2 为 Books 类型 */

	/* book 1 描述 */
	book1.title = "Go 语言"
	book1.author = "www.runoob.com"
	book1.subject = "Go 语言教程"
	book1.bookId = 6495407

	/* book 2 描述 */
	book2.title = "Python 教程"
	book2.author = "www.runoob.com"
	book2.subject = "Python 语言教程"
	book2.bookId = 6495700

	printBook(book1)
	printBook(book2)
	printBookPointer(&book2)
}

func printBook(book Books) {
	/* 打印 Book1 信息 */
	fmt.Printf("Book title : %s\n", book.title)
	fmt.Printf("Book author : %s\n", book.author)
	fmt.Printf("Book subject : %s\n", book.subject)
	fmt.Printf("Book book_id : %d\n", book.bookId)
}

/**
 * 指针函数
 */
func printBookPointer(book *Books) {
	/* 打印 Book1 信息 */
	fmt.Println("pointer function==========")
	fmt.Printf("Book title : %s\n", book.title)
	fmt.Printf("Book author : %s\n", book.author)
	fmt.Printf("Book subject : %s\n", book.subject)
	fmt.Printf("Book bookId : %d\n", book.bookId)
}

/**
 * 定义结构体
 */
type Books struct {
	title   string
	author  string
	subject string
	bookId  int
}
